
/*
PIC32MX795F512L 3.2" TFT LCD Demo Board Hardware Profile for Microchip Libraries
Copyright (C) 2012 Craig Dawson, Aaron Mohtar, Craig Peacock

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef _HARDWAREPROFILE_H_
#define _HARDWAREPROFILE_H_

#define GetSystemClock()            (80000000ul)
#define GetPeripheralClock()        (GetSystemClock()/2)
#define GetInstructionClock()       (GetSystemClock())

#define USE_SD_INTERFACE_WITH_SPI
//#define USE_USB_INTERFACE

#define SPI_FREQUENCY       (2000000)

// Secure Digital (SD) Card Chip Select
#define SD_CS		PORTDbits.RD14
#define SD_CS_TRIS	TRISDbits.TRISD14

// Secure Digital (SD) Card Detect
#define SD_CD		PORTEbits.RE9
#define SD_CD_TRIS	TRISEbits.TRISE9

// Secure Digital (SD) Write Enable
// We don't have a Write Enable I/O pin on the uSD card.
// Hardcode WE to 1 (enable)
#define SD_WE   1
#define SD_WE_TRIS      TRISEbits.TRISE9

// Use SPI3 - Map Registers
#define SPICON1         SPI3CON
#define SPISTAT		SPI3STAT
#define SPIBUF		SPI3BUF
#define SPISTAT_RBF	SPI3STATbits.SPIRBF
#define SPICON1bits	SPI3CONbits
#define SPISTATbits	SPI3STATbits
#define SPIENABLE       SPI3CONbits.ON
#define SPIBRG          SPI3BRG

// Map SPI3 direction pins
#define SPICLOCK	TRISDbits.TRISD15
#define SPIIN           TRISFbits.TRISF8
#define SPIOUT		TRISFbits.TRISF2

// Map SPI3 peripheral library functions.
// The legacy putcSPI()/getcSPI()/OpenSPI1() functions do not exist for
// SPI3 and SPI4, hence we use the SpiChannelXX functions.
#define putcSPI(data_out)   SpiChnPutC(3,data_out)
#define getcSPI()           SpiChnGetC(3)

#define SPI_START_CFG_1     (SPI_OPEN_MSTEN | SPI_OPEN_CKE_REV | SPI_OPEN_SMP_END)
#define SPI_START_CFG_2     (80000000/SPI_FREQUENCY)

#define OpenSPI(oFlags, srcClkDiv)  SpiChnOpen(3, oFlags, srcClkDiv)

#endif
